
package com.examsystem.service.impl;


import com.examsystem.dao.PaperQuestionMapper;
import com.examsystem.dao.QuestionMapper;
import com.examsystem.dao.UserMapper;
import com.examsystem.service.PaperQuestionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import static com.examsystem.Const.ConstMsg.CHECK_MSG_FAIL_MSG;
import static com.examsystem.Const.ConstMsg.GET_PAPER_QUESTION_FAIL_MSG;

/**
 * @author fire'ge
 */
@Service("paperQuestionServiceImpl")
public class PaperQuestionServiceImpl implements PaperQuestionService {
    @Resource
    private PaperQuestionMapper paperQuestionMapper;
    @Resource
    private UserMapper userMapper;
    @Resource
    private QuestionMapper questionMapper;
    @Override
    public int getPqId(int paperId, int questionId) {
        boolean flag = userMapper.queryUserById(questionId)==null||questionMapper.queryQuestionById(questionId)==null;
        if (flag){
            throw new RuntimeException(CHECK_MSG_FAIL_MSG);
        }

        int queryPaperQuestionByPaperAndQuestion = paperQuestionMapper.queryPaperQuestionByPaperAndQuestion(questionId, paperId);

        if (queryPaperQuestionByPaperAndQuestion==0){
            throw new RuntimeException(GET_PAPER_QUESTION_FAIL_MSG);
        }
        return queryPaperQuestionByPaperAndQuestion;
    }
}
